# encoding: utf-8
# @author: wangxin
# @software: garner
# @file: SmsViews.py
# @time: 2025/2/18 20:08
import random

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
from django.http import HttpResponse, JsonResponse
from django.views import View
from django_redis import get_redis_connection



from SMS.sendSms import sendSms


# pip install aliyun-python-sdk-core
# pip install aliyun-python-sdk-dysmsapi

class SmsCodeView(View):
    def get(self, request):

        uuid = request.GET.get('uuid')
        if uuid is None:
            return HttpResponse("没有uuid")
        #获取redis验证码
        redis_conn = get_redis_connection('default')
        image_code=redis_conn.get('image_code:%s' % uuid)

        if image_code is None:
            return HttpResponse("验证码过期")

        # 获取地址栏验证码
        H_code = request.GET.get('image_code')
        # 校验验证码
        if image_code.decode('utf-8').lower() != H_code.lower():
            return HttpResponse("验证码错误")
        phone=request.GET.get('mobile')
        response = sendSms(phone)
        return JsonResponse(response, safe=False)


